package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.GpsPosTraceDao;
import cn.topevery.garden.entity.po.GpsPosTrace;
import cn.topevery.garden.entity.query.GpsPosTraceQuery;
import cn.topevery.garden.entity.vo.CarVO;
import cn.topevery.garden.entity.vo.GpsPosTraceVO;
import cn.topevery.garden.entity.vo.PersonVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * GPS详情
 *
 * @author code-generate
 * @date 2021-09-13
 */
@Service
public class GpsPosTraceLogic extends BaseLogic<GpsPosTrace> {
    @Autowired
    GpsPosTraceDao gpsPosTraceDao;

    @Autowired
    private PersonLogic personLogic;

    @Autowired
    private CarLogic carLogic;

    @Override
    public BaseEntityDao<GpsPosTrace, Integer> getDao() {
        return gpsPosTraceDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<GpsPosTraceVO> listPage(GpsPosTraceQuery query) {
        if (query.getObjType() == 0) {
            PersonVO personVO = personLogic.getByUserId(query.getObjId());
            query.setId(personVO.getId());
            return gpsPosTraceDao.listPage(personVO.getName(), query);
        } else {
            CarVO carVO = carLogic.getByCarId(query.getObjId());
            query.setId(carVO.getId());
            return gpsPosTraceDao.listPage(carVO.getCarNum(), query);
        }

    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        gpsPosTraceDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param gpsPosTrace 实体
     */
    public void saveOrUpdate(String userId, GpsPosTrace gpsPosTrace){
        gpsPosTraceDao.saveOrUpdate(userId,gpsPosTrace);
    }
}
